package arithmetic

import (
	"codejy/calculate"
	"codejy/globalfunc"
	"strconv"
)

type IncrementArithmeticCalculate struct {
	name          string                  //计算器名称
	priority      int                     //优先级
	calculateData calculate.CalculateData //计算器数据
	result        string                  //计算结果

}

func init() {
	//注册计算器
	calculate.RegisterCalculate(&IncrementArithmeticCalculate{
		name:     "++",
		priority: 3,
	})
}

func (a *IncrementArithmeticCalculate) GetName() string {
	return a.name
}

func (a *IncrementArithmeticCalculate) IsBool(symbol string) bool {
	if symbol == a.name {
		// 判断是否是数字或者字符串
		b2 := globalfunc.ExecuteFunc("IsInt", a.calculateData.B).(bool)
		if b2 {
			return true
		}
		panic("自增运算必须是整数字: " + a.calculateData.B + "++")
	}
	return false
}

func (a *IncrementArithmeticCalculate) AddExpression(a1, symbol, b1 string) {
	a.calculateData = calculate.CalculateData{
		A:      a1,
		Symbol: symbol,
		B:      b1,
	}
}

func (a *IncrementArithmeticCalculate) Calculate() {
	B1, _ := strconv.Atoi(a.calculateData.B)
	a.result = strconv.Itoa(B1 + 1)
}

func (a *IncrementArithmeticCalculate) GetResult() string {
	return a.result
}

func (a *IncrementArithmeticCalculate) GetPriority() int {
	return a.priority
}
